package org.jeecg.modules.demo.crm.glm.util;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class JsonUtils {
    public static final String API_KEY = "548b762133944e4c99546ac59ba22efb.4z5xXWg0MDMplYqM"; // 替换为你的API Key
    public static final String MODEL_URL = "https://open.bigmodel.cn/api/paas/v4/chat/completions";


    public static String createRequestJsonImages(String url,String prompt) {
        JSONObject message = new JSONObject();
        message.put("role", "user");
        JSONArray contents = new JSONArray();
        JSONObject content = new JSONObject();
        content.put("type", "text");
        content.put("text", prompt);
        contents.add(content);

        JSONObject content2 = new JSONObject();
        content2.put("type", "image_url");
        JSONObject image_url = new JSONObject();
        image_url.put("url", url);
        content2.put("image_url",image_url);
        contents.add(content2);
        message.put("content", contents);
        JSONArray messagesArray = new JSONArray();
        messagesArray.add(message);
        JSONObject requestBody = new JSONObject();
        requestBody.put("model", "glm-4v-flash");
        requestBody.put("messages", messagesArray);
        return requestBody.toString();
    }

    public static String createRequestJson(String body) {
        JSONObject message = new JSONObject();
        message.put("role", "user");
        message.put("content",  fapiaopromptTxt.replace("{body}",body));
        JSONArray messagesArray = new JSONArray();
        messagesArray.add(message);
        JSONObject requestBody = new JSONObject();
        requestBody.put("model", "glm-4-flashx");
        requestBody.put("messages", messagesArray);
        return requestBody.toString();
    }

    public static String fapiaopromptTxt ="{\n" +
            "    \"task\": \"从提供的body中的发票信息中抽取关键字段并生成JSON数据。\",\n" +
            "    \"input\": {\n" +
            "\t\t\"body\":\"{body}\"\n" +
            "        \"fields\": [\n" +
            "            \"发票类型\",\n" +
            "            \"发票号码\",\n" +
            "            \"开票日期\",\n" +
            "            \"购买方名称\",\n" +
            "            \"购买方统一社会信用代码/纳税人识别号\",\n" +
            "            \"销售方名称\",\n" +
            "            \"销售方统一社会信用代码/纳税人识别号\",\n" +
            "            \"销售方开户银行\",\n" +
            "            \"销售方银行账号\",\n" +
            "            \"项目名称\",\n" +
            "            \"建筑服务发生地\",\n" +
            "            \"建筑项目名称\",\n" +
            "            \"金额\",\n" +
            "            \"税率/征收率\",\n" +
            "            \"税额\",\n" +
            "            \"合计金额\",\n" +
            "            \"合计税额\",\n" +
            "            \"价税合计（大写）\",\n" +
            "            \"价税合计（小写）\",\n" +
            "            \"备注\",\n" +
            "            \"开票人\"\n" +
            "        ]\n" +
            "    },\n" +
            "    \"outputFormat\": {\n" +
            "        \"type\": \"jsonArray\",\n" +
            "        \"structure\": {\n" +
            "            \"购买方信息\": {\n" +
            "                {\n" +
            "                    \"key\": \"名称\",\n" +
            "                    \"type\": \"integer\"\n" +
            "                },\n" +
            "                {\n" +
            "                    \"key\": \"统一社会信用代码/纳税人识别号\",\n" +
            "                    \"type\": \"integer\"\n" +
            "                }\n" +
            "            },\n" +
            "            \"销售方信息\": {\n" +
            "                {\n" +
            "                    \"key\": \"名称\",\n" +
            "                    \"type\": \"string\"\n" +
            "                },\n" +
            "                {\n" +
            "                    \"key\": \"统一社会信用代码/纳税人识别号\",\n" +
            "                    \"type\": \"string\"\n" +
            "                },\n" +
            "            },\n" +
            "            \"合计\": {\n" +
            "                {\n" +
            "                    \"key\": \"金额\",\n" +
            "                    \"type\": \"string\"\n" +
            "                },\n" +
            "                {\n" +
            "                    \"key\": \"税额\",\n" +
            "                    \"type\": \"string\"\n" +
            "                },\n" +
            "            },\n" +
            "            {\n" +
            "                \"key\": \"发票号码\",\n" +
            "                \"type\": \"string\"\n" +
            "            },\n" +
            "            {\n" +
            "                \"key\": \"开票日期\",\n" +
            "                \"type\": \"string\"\n" +
            "            },\n" +
            "            {\n" +
            "                \"key\": \"发票类型\",\n" +
            "                \"type\": \"string\"\n" +
            "            },\n" +
            "            {\n" +
            "                \"key\": \"项目名称\",\n" +
            "                \"type\": \"string\"\n" +
            "            },\n" +
            "            {\n" +
            "                \"key\": \"金额\",\n" +
            "                \"type\": \"string\"\n" +
            "            },\n" +
            "            {\n" +
            "                \"key\": \"税率/征收率\",\n" +
            "                \"type\": \"string\"\n" +
            "            },\n" +
            "            {\n" +
            "                \"key\": \"税额\",\n" +
            "                \"type\": \"string\"\n" +
            "            },\n" +
            "            {\n" +
            "                \"key\": \"备注\",\n" +
            "                \"type\": \"string\"\n" +
            "            },\n" +
            "            {\n" +
            "                \"key\": \"开票人\",\n" +
            "                \"type\": \"string\"\n" +
            "            },\n" +
            "        }\n" +
            "    }\n" +
            "}";

    public static String fapiaoprompt ="{\n" +
            "    \"task\": \"从提供的发票信息中抽取关键字段并生成JSON数据。\",\n" +
            "    \"input\": {\n" +
            "        \"image\": \"path_to_your_image.jpg\",\n" +
            "        \"fields\": [\n" +
            "            \"购买方->名称\",\n" +
            "            \"购买方->统一社会信用代码/纳税人识别号\",\n" +
            "            \"销售方->名称\",\n" +
            "            \"销售方->统一社会信用代码/纳税人识别号\",\n" +
            "            \"合计->金额\",\n" +
            "            \"合计->税额\",\n" +
            "            \"发票类型\",\n" +
            "            \"发票号码\",\n" +
            "            \"建筑服务发生地\",\n" +
            "            \"建筑项目名称\",\n" +
            "            \"开票日期\",\n" +
            "            \"项目名称\",\n" +
            "            \"金额\",\n" +
            "            \"税率/征收率\",\n" +
            "            \"税额\",\n" +
            "            \"价税合计（大写）\",\n" +
            "            \"价税合计（小写）\",\n" +
            "            \"备注\",\n" +
            "            \"开票人\"\n" +
            "        ]\n" +
            "    },\n" +
            "    \"outputFormat\": {\n" +
            "        \"type\": \"jsonArray\",\n" +
            "        \"structure\": {\n" +
            "            \"购买方信息\": {\n" +
            "                \"名称\": \"string\",\n" +
            "                \"统一社会信用代码/纳税人识别号\": \"string\"\n" +
            "            },\n" +
            "            \"销售方信息\": {\n" +
            "                \"名称\": \"string\",\n" +
            "                \"统一社会信用代码/纳税人识别号\": \"string\"\n" +
            "            },\n" +
            "            \"合计\": {\n" +
            "                \"金额\": \"string\",\n" +
            "                \"税额\": \"string\"\n" +
            "            },\n" +
            "            \"基础信息\": {\n" +
            "                \"项目名称\": \"string\",\n" +
            "                \"发票号码\": \"string\",\n" +
            "                \"开票日期\": \"string\",\n" +
            "                \"发票类型\": \"string\",\n" +
            "                \"税额\": \"string\",\n" +
            "                \"金额\": \"string\",\n" +
            "                \"税率/征收率\": \"string\",\n" +
            "                \"价税合计（大写）\": \"string\",\n" +
            "                \"价税合计（小写）\": \"string\",\n" +
            "                \"备注\": \"string\",\n" +
            "                \"建筑服务发生地\": \"string\",\n" +
            "                \"建筑项目名称\": \"string\",\n" +
            "                \"开票人\": \"string\"\n" +
            "            }\n" +
            "        }\n" +
            "    }\n" +
            "}";


    public static String additional_prompt ="{\n" +
            "    \"task\": \"从提供的图片信息中抽取关键字段并生成JSON数据。注意这是一张table格式的数据\",\n" +
            "    \"input\": {\n" +
            "        \"image\": \"path_to_your_image.jpg\",\n" +
            "        \"fields\": [\n" +
            "            \"标题\",\n" +
            "            \"项目编号\",\n" +
            "            \"申请人\",\n" +
            "            \"申请日期\",\n" +
            "            \"所属部门\",\n" +
            "            \"项目名称\",\n" +
            "            \"仓库\",\n" +
            "            \"需求类型\",\n" +
            "            \"期望完成日期\",\n" +
            "            \"预计完成日期\",\n" +
            "            \"优先级\",\n" +
            "            \"直接维修\",\n" +
            "            \"品牌、型号(采购适用)\"\n" +
            "            \"数量(采购适用)\"\n" +
            "            \"预估费用(设备部填写)\"\n" +
            "            \"申请原因\"\n" +
            "            \"申请内容\"\n" +
            "            \"维修/维保服务验收要求\"\n" +
            "        ]\n" +
            "    },\n" +
            "    \"outputFormat\": {\n" +
            "        \"type\": \"jsonArray\",\n" +
            "        \"structure\": {\n" +
            "                \"\": \"string\",\n" +
            "                \"\": \"string\",\n" +
            "                \"申请人\": \"string\",\n" +
            "                \"申请日期\": \"string\",\n" +
            "                \"所属部门\": \"string\",\n" +
            "                \"项目名称\": \"string\",\n" +
            "                \"仓库\": \"string\",\n" +
            "                \"需求类型\": \"string\",\n" +
            "                \"期望完成日期\": \"string\",\n" +
            "                \"预计完成日期\": \"string\",\n" +
            "                \"优先级\": \"string\",\n" +
            "                \"直接维修\": \"string\",\n" +
            "                \"品牌、型号(采购适用)\": \"string\"\n" +
            "                \"数量(采购适用)\": \"string\"\n" +
            "                \"预估费用(设备部填写)\": \"string\"\n" +
            "                \"申请原因\": \"string\"\n" +
            "                \"申请内容\": \"string\"\n" +
            "                \"维修/维保服务验收要求\": \"string\"\n" +
            "        }\n" +
            "    }\n" +
            "}";


    public static String promptImages ="{\n" +
            "  \"task\": \"Extract data from the provided image and return the results in a JSON array format. Do not include explanations, only the extracted data.\",\n" +
            "  \"input\": {\n" +
            "    \"image\": \"path_to_your_image.jpg\",\n" +
            "    \"fields\": [\"序号\", \"名称\", \"数量\", \"单位\", \"主材\", \"辅材\", \"人工\", \"总计\", \"备注\"]\n" +
            "  },\n" +
            "  \"outputFormat\": {\n" +
            "    \"type\": \"jsonArray\",\n" +
            "    \"structure\": [\n" +
            "      {\"key\": \"序号\", \"type\": \"integer\"},\n" +
            "      {\"key\": \"名称\", \"type\": \"string\"},\n" +
            "      {\"key\": \"数量\", \"type\": \"integer\"},\n" +
            "      {\"key\": \"单位\", \"type\": \"string\"},\n" +
            "      {\"key\": \"主材\", \"type\": \"float\"},\n" +
            "      {\"key\": \"辅材\", \"type\": \"float\"},\n" +
            "      {\"key\": \"人工\", \"type\": \"float\"},\n" +
            "      {\"key\": \"总计\", \"type\": \"float\"},\n" +
            "      {\"key\": \"备注\", \"type\": \"string\"}\n" +
            "    ]\n" +
            "  }\n" +
            "}\n";

    public static String quote_ocr_prompt ="{\n" +
            "  \"task\": \"Extract data from the provided image and return the results in a JSON array format. Do not include explanations, only the extracted data.\",\n" +
            "  \"input\": {\n" +
            "    \"image\": \"path_to_your_image.jpg\",\n" +
            "    \"fields\": [\"名称\", \"数量\", \"单位\", \"主材\", \"辅材\",  \"人工\",  \"备注\"]\n" +
            "  },\n" +
            "  \"outputFormat\": {\n" +
            "    \"type\": \"jsonArray\",\n" +
            "    \"structure\": [\n" +
            "      {\"key\": \"序号\", \"type\": \"integer\"},\n" +
            "      {\"key\": \"名称\", \"type\": \"string\"},\n" +
            "      {\"key\": \"数量\", \"type\": \"integer\"},\n" +
            "      {\"key\": \"单位\", \"type\": \"string\"},\n" +
            "      {\"key\": \"主材\", \"type\": \"float\"},\n" +
            "      {\"key\": \"辅材\", \"type\": \"float\"},\n" +
            "      {\"key\": \"人工\", \"type\": \"float\"},\n" +
            "      {\"key\": \"备注\", \"type\": \"string\"}\n" +
            "    ]\n" +
            "  }\n" +
            "}\n";


}